#!/usr/bin/perl

use Data::Dumper;
use Net::DirectConnect::clihub;
my $dc = Net::DirectConnect::clihub->new(
    'host' => 'ipse.zapto.org',
    'port' => '4111', #if not 411
    'Nick' => 'Bender', 
    'description' => 'kill all humans',
    'M'           => 'P', #passive mode, active by default
);
$dc->wait_connect();
#$dc->chatline( 'hi all' );

$dc->{'handler'}{'chatline'} = sub {
  my $dc = shift;
  my ( $nick, $text ) = $_[0] =~ /^<([^>]+)> (.+)$/;
  print "My chatline handler [$nick,$text]\n";
  if ( $text =~ /^\s*moo/i ) {         # if you type  !moo  in main chat
    $dc->cmd( 'chatline', 'meow!' );    # via cmd,     can be written as $dc->chatline( ...
    $dc->To( $nick, 'woof!' );          # private msg, can be written as $dc->cmd('To', $nick, ...
  }
};


while ( $dc->active() ) {
    $dc->work();
}
$dc->destroy();